<template>
  <div v-if="browserRedirect">
    <div>
      <div class="table-page-search-wrapper" v-show="showSizer">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="6" :sm="8">
              <a-form-item label="店铺名称">
                <a-input placeholder="请输入店铺名称" v-model="shopName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="店家手机号码">
                <a-input placeholder="请输入店家手机号码" v-model="shopPhone"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8" >
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                <!-- <a-button type="primary" style="margin-left: 8px" icon="download" @click="handleExportXls('客户表')">导出</a-button> -->
              </span>
            </a-col>
  
          </a-row>
        </a-form>
      </div>
      <a-tabs default-active-key="1" size="large" :tab-bar-style="{marginBottom: '24px', paddingLeft: '16px'}">
        <div class="extra-wrapper" slot="tabBarExtraContent">
          <div class="selSty" @click="showSizer=!showSizer" style="line-height: 60px;">
            <span>筛选</span>
            <img style='margin-top: -3px;margin-left: 3px;' src="../../assets/common-icon-filter.svg">
          </div>
        </div>
        <a-tab-pane loading="true" tab="正版剧本绑定概览" key="1" style="min-height: 100vh;">
          <ul style="margin: 0;padding:0;list-style-type: none;">
            <li v-for="val in dataSource" class="liCommSty">
              <div style="border-bottom: 1px solid #EBEBEB;padding-bottom: 10px;">
                <div style="color: #333;font-weight: bold;">
                  <span>{{val.shopName}}</span>
                </div>
              </div>
              <div style="margin-top: 10px;">
                <span style="color: #333;">店家手机号</span>
                <span style="float: right;">{{val.shopPhone}}</span>
              </div>
              <div style="margin-top: 10px;">
                <span style="color: #333;">门店地址</span>
                <span style="float: right;">{{val.shopAddress}}</span>
              </div>
              <div style="margin-top: 10px;">
                <span style="color: #333;">绑定剧本</span>
                <ul style="list-style: none;float: right;display: inline-block;">
                  <li style="display:inline-block;margin-right: 5px;" v-for="val in val.bindGoods">『{{val}}』</li>
                </ul>
              </div>
            </li>
          </ul>
          <a-pagination style="float: right;margin-top:5px;" showQuickJumper :defaultCurrent="ipagination.current" :total="ipagination.total" @change="onChange"/>
        </a-tab-pane>
      </a-tabs>
    </div>
  </div>
  <a-card v-else :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="店铺名称">
              <a-input placeholder="请输入店铺名称" v-model="shopName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="店家手机号码">
              <a-input placeholder="请输入店家手机号码" v-model="shopPhone"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a-button type="primary" style="margin-left: 8px" icon="download" @click="handleExportXls('客户表')">导出</a-button> -->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->   
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('客户表')">导出</a-button> -->
      <!-- <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        @change="handleTableChange"
        >

        <template slot="goodList" slot-scope="text">
          <ul style="list-style: none;">
            <li v-for="val in text">{{val}}</li>
          </ul>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <div v-else @click="jumpProview(text)">
            <img :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
          </div>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <JProviewImg v-if="showImg" @closeProview="closeProview" :imgurl="proviewUrl"></JProviewImg>
  </a-card>
</template>

<script>
  import { browserRedirect } from '@/utils/util'
  import { getAction } from '@/api/manage'
  import {initDictOptions, filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import JProviewImg from '@/components/jeecg/JProviewImg.vue'

  export default {
    name: "BlockCustomerInfoList",
    components: {
      JProviewImg
    },
    data () {
      return {
        browserRedirect:false,
        showSizer:false,
        description: '客户表管理页面',
        shopName:"",
        shopPhone:"",
        userAuth2btn:"",
        dataSource:[],
        // 表头
        columns: [
          {
            title:'店铺名称',
            align:"center",
            dataIndex: 'shopName'
          },
          {
            title:'门店地址',
            align:"center",
            dataIndex: 'shopAddress'
          },
          {
            title:'店家手机号',
            align:"center",
            dataIndex: 'shopPhone'
          },
          {
            title:'绑定剧本',
            align:"center",
            dataIndex: 'bindGoods',
            scopedSlots: { customRender: 'goodList' }
          }
        ],
        ipagination:{
          current: 1,
          pageSize: 10,
          showSizeChanger:false,
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          total: 0
        },
        dictOptions:{
         authStatus:[],
        },
        showImg:false,
        proviewUrl:""
      }
    },
    mounted(){
      var that = this;
      this.browserRedirect = browserRedirect();
      getAction("/block/blockManufacturerInfo/userAuth2btn")
        .then(res => {
          if (res.success) {
            that.userAuth2btn = res.result.status;
            if(that.userAuth2btn == 3){
              that.issuerId = "";
              this.listInfo();
              return
            }
            let list={
              column: "createTime",
              order: "desc",
              field: "id,,factoryName,companyProfile,createTime,type,name,status,address,phone,imageurl,action",
              pageNo: 1,
              pageSize: 5
            };
            getAction("/block/blockManufacturerInfo/list",list).then((res)=>{
              if (res.success) {
                this.issuerId = res.result.records[0].id;
                this.listInfo();
              } else {
                this.$message.warning(res.message)
              }
            })
          } else {
            this.$message.warning(res.message)
          }
        })
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      onChange(pageNumber) {
        this.ipagination.current = pageNumber;
        this.handleTableChange(this.ipagination,{},{});
      },
      listInfo(){
        getAction("https://blockinsight.com.cn/scriptPlay/third/shopInfoOverview?currentPage=1&pageSize=10&issuerId="+this.issuerId).then((res) => {
          if (res.success) {
            this.dataSource = res.data.data;
            this.ipagination.total = res.data.totalSize;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
        })
      },
      searchReset(){
        this.shopName = "";
        this.shopPhone = "";
        this.searchQuery();
      },
      searchQuery(){
        this.ipagination.current = 1;
        let urlStr=encodeURI("https://blockinsight.com.cn/scriptPlay/third/shopInfoOverview?currentPage=1&pageSize=10&shopName="+this.shopName+"&shopPhone="+this.shopPhone+"&issuerId="+this.issuerId);
        getAction(urlStr).then((res) => {
          if (res.success) {
            this.dataSource = res.data.data;
            this.ipagination.total = res.data.totalSize;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
        })
      },
      handleTableChange(pagination, filters, sorter){
        this.ipagination = pagination;
        let url = "https://blockinsight.com.cn/scriptPlay/third/shopInfoOverview?currentPage="+pagination.current+"&pageSize=10&shopName="+this.shopName+"&shopPhone="+this.shopPhone+"&issuerId="+this.issuerId
        getAction().then((res) => {
          if (res.success) {
            this.dataSource = res.data.data;
            this.ipagination.total = res.data.totalSize;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
        })
      },
      closeProview(){
        this.showImg = false;
      },
      jumpProview(val){
        this.showImg = true;
        this.proviewUrl = window._CONFIG['imgDomainURL']+'/'+val;
      }
       
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>